package com.leyou.utils;

import java.util.UUID;

public class UuidUtils {

    public static String uuid() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * <p>根据文件名获取文件后缀，包含.</p>
     * <p>例如："abc.jpg"，返回 ".jpg"</p>
     * @param fileName
     * @return
     */
    public static String getFileSuffix(String fileName) {
        return fileName.substring(fileName.lastIndexOf("."), fileName.length());
    }

    /**
     * 构建/生成文件名
     * @param fileName
     * @return
     */
    public static String genFileName(String fileName){
        return uuid() + getFileSuffix(fileName);
    }

//    public static void main(String[] args) {
//        String imgName = "abc.jpg";
//        System.out.println(uuid());
//        System.out.println(imgName.lastIndexOf("."));
//        System.out.println(imgName.substring(0, 3));
//        String suffix = imgName.substring(imgName.lastIndexOf("."), imgName.length());
//        System.out.println(suffix);
//        System.out.println(getFileSuffix(imgName));
//        System.out.println(genFileName(imgName));
//    }
}
